package com.sky.myapplication.kotlin.kotlinActivity

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.PagerTabStrip
import androidx.viewpager.widget.ViewPager
import com.sky.myapplication.R
import com.sky.myapplication.kotlin.kotlinFragment.ViewPageFragment

/**
 * @Author: Minxp
 * @UpdateDate: 2021/7/7 0007
 * @Description: ViewPage
 */
class ViewPageFragmentKotlinActivity: AppCompatActivity() {
    lateinit var vp_body: ViewPager
    lateinit var pts_title: PagerTabStrip

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_page)

        initView()
        initData()
    }

    fun initView(){
        vp_body = findViewById(R.id.vp_body)
        pts_title = findViewById(R.id.pts_title)
    }

    fun initData(){
        pts_title.visibility = View.GONE


        var data = ArrayList<Fragment>()

        for (index in 1..3){
            var fragment = ViewPageFragment()
            val bundle = Bundle()
            bundle.putString("content", "第"+index.toString()+"个 Fragment")
            fragment.arguments = bundle
            data.add(fragment)
        }

        vp_body.adapter = object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {
                return data.size
            }

            override fun getItem(position: Int): Fragment {
                return data[position]
            }

        }
    }
}